package com.scfire.project

import com.scfire.security.Member

class FeedBackService {

	Member system;
	//给定的唯一代表系统的用户
	private setSys(){
		system= Member.findByUsername("SYSTEM_OPEATOR_UNIQUE");
	}
	
	//author = admin;date = now
	public  void insertFeedBack(String content, String projectid, String s){
		setSys()
		
		insertFeedBack(content, projectid, new Date(),s);
	}
	
	//author = admin
	public  void insertFeedBack(String content, String projectid, Date publishDate,String s){
		 def member2 = setSys()
		insertFeedBack(content, projectid, publishDate, Integer.parseInt(member2.id+""),s);
	}
	
	public  void insertFeedBack(String content, String projectid, Date publishDate, int author,String s){
		
		ProjectFeedback feedback = new ProjectFeedback()
		feedback.text = content;
		feedback.member = author;
		feedback.date = publishDate;
		feedback.feedbackType=s
		try{
			feedback.project = Integer.parseInt(projectid);
			feedback.save (flush: true)
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public  void insertFeedBacks(String content, String projectid, int author, List<String> list,String s){
		ProjectFeedback feedback = new ProjectFeedback()
		feedback.text = content;
		feedback.member = author;
		feedback.date = new Date();
		
		if(list.size()>0){
			feedback.img1=list.get(0)
			feedback.img2=list.get(1)
			feedback.img3=list.get(2)
			feedback.img4=list.get(3)
		}
		
		feedback.feedbackType=s
		
		try{
			feedback.project = Integer.parseInt(projectid);
			feedback.save (flush: true)
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}

}
